package com.erju.controller;

import cn.hutool.core.date.DateUtil;
import com.erju.pojo.SlLab;
import com.erju.pojo.SlLabAppointment;
import com.erju.pojo.VO.LabReviewVo;
import com.erju.service.LabAppointmentService;
import com.erju.utils.Result;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;

/**
 * @Description:
 * @author: erju
 * @date: 2022.03.29
 */
@RequestMapping("/labAppointment")
@RestController
@Slf4j
public class LabAppointmentController {

    @Autowired
    LabAppointmentService labAppointmentService;

    /***
     *查询实验室预约详情
     * @Author erju
     * @Date 16:06 2022/3/26
     * @Param [slLab]
     * @return com.erju.utils.Result<?>
     **/
    @RequestMapping("/selectLabDetails")
    public Result<?> selectLabDetails(@RequestBody SlLabAppointment slLabAppointment) {
        return labAppointmentService.selectLabDetails(slLabAppointment);
    }

    /***
     *添加实验室预约信息
     * @Author erju
     * @Date 20:52 2022/3/28
     * @Param [slLabAppointment]
     * @return com.erju.utils.Result<?>
     **/
    @RequestMapping("/addAppointment")
    public Result<?> addAppointment(@RequestBody SlLabAppointment slLabAppointment) throws Exception {
//        if(hashMap.isEmpty()){
//            throw new Exception();
//        };
        log.info(slLabAppointment.toString());
        return labAppointmentService.addAppointment(slLabAppointment);
    }

    /***
     *管理员查询预约信息并审批
     * @Author erju
     * @Date 16:06 2022/3/29
     * @Param [slLab]
     * @return com.erju.utils.Result<?>
     **/
    @RequestMapping("/selectAppointmentByFlag/{pageNum}")
    public Result<?> selectAppointmentByFlag(@RequestBody LabReviewVo labReviewVo ,@PathVariable("pageNum") int pageNum) {
        log.info("接受过来的参数" + labReviewVo.toString());
        log.info("查询页面参数" + pageNum);
        PageHelper.startPage(pageNum, 10);
        return labAppointmentService.selectAppointmentByFlag(labReviewVo);
    }

    /**
     * 更新审批状态
     *
     * @param slLabAppointment
     * @return
     */
    @RequestMapping("/updateAppointmentFlag")
    public Result<?> updateAppointmentFlag(@RequestBody SlLabAppointment slLabAppointment) {
        log.info("接受过来的参数" + slLabAppointment.toString());
        return labAppointmentService.updateAppointmentFlag(slLabAppointment);
    }


    /**
     * 个人预约座位选座
     * @param
     * @return
     */
    @RequestMapping("/selectPersonalLabSeat")
    public Result<?> selectPersonalLabSeat(@RequestBody SlLabAppointment slLabAppointment) throws Exception {
        log.info("开始查询实验室座位------"+slLabAppointment.toString());
        if(slLabAppointment.getAppointment_time()==null){
            throw new Exception("实验室预约时间为空");
        }
        return  labAppointmentService.selectPersonalLabSeat(slLabAppointment);
    }


    /**
     * 教学实验室查询已经添加的学生
     * @param
     * @return
     */
    @RequestMapping(value = "/selectLabAppointmentStudent/{lab_appointment_id}",method = RequestMethod.GET)
    public Result<?> selectLabAppointmentStudent(@PathVariable(name="lab_appointment_id") Integer lab_appointment_id) throws Exception {
        return  labAppointmentService.selectLabAppointmentStudent(lab_appointment_id);
    }

    @RequestMapping(value = "/addLabAppointmentStudent/{lab_appointment_student_id_list}/{appointment_id}",method = RequestMethod.GET)
    public Result<?> addLabAppointmentStudent(@PathVariable(name="lab_appointment_student_id_list") String lab_appointment_student_id_list,@PathVariable(name="appointment_id") Integer appointment_id) throws Exception {
        log.info("接收的参数----------->"+lab_appointment_student_id_list);
        return  labAppointmentService.addLabAppointmentStudent(lab_appointment_student_id_list,appointment_id);
    }
}
